process {

    publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

    withName: '.*:BAM_SORT_STATS_SAMTOOLS:SAMTOOLS_.*' {
        ext.prefix = { "${meta.id}.sorted" }
    }

    withName: '.*:BAM_SORT_STATS_SAMTOOLS:BAM_STATS_SAMTOOLS:.*' {
        ext.prefix = { "${meta.id}.sorted.bam" }
    }
}
